# coding=utf-8

from selenium import webdriver
import json
file = 'cookies.json'

# 打开网址
def open_url(url,driver):
    driver.get(url)
    driver.delete_all_cookies()
    driver.implicitly_wait(5)
    driver.maximize_window()

def save_cookies(driver):
    cookies = driver.get_cookies()
    fp = open(file, 'w')
    jsonCookies = json.dumps(cookies)
    # 登录完成后，将cookie保存到本地文件
    with open(file, 'w') as f:
        f.write(jsonCookies)
    fp.close()

if __name__ == '__main__':
    driver = webdriver.Firefox()
    open_url("https://www.toutiao.com", driver)
    key= input("请输入")
    if key =='login':
        save_cookies(driver)
    driver.close()
